package com.hawk.eye.client.config;

import com.hawk.eye.common.utils.StringUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.MutablePropertySources;

import java.util.HashMap;
import java.util.Map;

/**
 * @className: HawkEyeConfigInitializer
 * @description: 初始化服务的主启动类所在包路径
 * @author: salad
 * @date: 2023/11/27
 **/
public class HawkEyeConfigInitializer implements EnvironmentPostProcessor, Ordered {


    @Override
    public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
        //记录用户主启动类所在包路径
        String property = environment.getProperty("hawk-eye.app-package-prefix");
        if (StringUtil.isBlank(property)) {
            String appPackage = application.getMainApplicationClass().getPackage().getName();
            System.setProperty("hawk-eye.app-package-prefix", appPackage);
        }

    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }

}
